package com.woniu.register.controller;

import com.woniu.common.util.Result;
import com.woniu.register.dto.PropDTO;
import com.woniu.register.dto.ProposerDTO;
import com.woniu.register.entity.Proposer;
import com.woniu.register.service.ProposerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 申请人控制表
 *
 * @author 晨星
 * @date 2022/12/13 14:34
 **/
@RestController
@RequestMapping("Proposers")
public class ProposerController {
    @Autowired
    private ProposerService proposerService;

    @PostMapping("add")
    public Result add(@RequestBody ProposerDTO proposer) {
        int i = proposerService.insertProposer(proposer);
        int proposerId = proposerService.selectId();
        if (i > 0) {
            return Result.ok().data("新增申请人成功",proposerId);
        } else {
            return Result.error();
        }
}
    @PostMapping("/padd")
    public int proposerAdd(@RequestBody Proposer proposer){
        int i = proposerService.insertSelective(proposer);
        return i;
    }

    @GetMapping("{proposerId}")
    public Result queryById(@PathVariable("proposerId") Long id) {
        Proposer proposer = proposerService.selectByPrimaryKey(id);
        return Result.ok().data("proposer", proposer);
    }

    @PutMapping("update")
    public Result update(@RequestBody PropDTO propDTO) {
        int i = proposerService.updateByPrimaryKeySelective(propDTO);
        if (i > 0) {
            return Result.ok();
        } else {
            return Result.error();
        }
    }




}
